package com.tianji.learning.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.exceptions.BadRequestException;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.po.LearningLesson;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author mxl
 * @since 2024-06-25
 */
@Api(tags = "我的课程相关接口")
@RestController
@RequestMapping("/lessons")
@RequiredArgsConstructor
public class LearningLessonController {

    final ILearningLessonService iLearningLessonService;

    @ApiOperation("分页查询我的课表")
    @GetMapping("page")
    public PageDTO<LearningLessonVO> queryMyLession(PageQuery query){
        return iLearningLessonService.queryMyLession(query);
    }

    @ApiOperation("查询正在学习的课程")
    @GetMapping("now")
    public LearningLessonVO queryMyCurrentLession(PageQuery query){
        return iLearningLessonService.queryMyCurrentLession(query);
    }

    @ApiOperation("根据课程ID删除课表内容")
    @PostMapping("delete/{courseId}")
    public void deleteLession(@PathVariable("courseId") Long courseId){
        iLearningLessonService.deleteLession(courseId);
    }

    @PostMapping("plans")
    @ApiOperation("创建学习计划")
    public void createLearningPlan(@RequestBody @Validated LearningPlanDTO dto){
        iLearningLessonService.createLearningPlan(dto);
    }

    @GetMapping("plans")
    @ApiOperation("分页查询我的课程计划")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return iLearningLessonService.queryMyPlans(pageQuery);
    }


    /**
     * 校验当前用户是否可以学习当前课程
     * @param courseId 课程id
     * @return lessonId，如果是报名了则返回lessonId，否则返回空
     */
    @ApiOperation("检验课程是否能够访问")
    @GetMapping("{courseId}/valid")
    public Long isLessonValid(@PathVariable("courseId") Long courseId){
        return iLearningLessonService.isLessonValid(courseId);
    }

    @ApiOperation("查询课程当前状态，是否正在学习等信息")
    @GetMapping("{courseId}")
    public LearningLessonVO queryState(@PathVariable("courseId") Long courseId){
        return iLearningLessonService.queryState(courseId);
    }

    @ApiOperation("查询课程报名人数")
    @GetMapping("/{courseId}/count")
    Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId){
        return iLearningLessonService.countLearningLessonByCourse(courseId);
    }



}
